/**
 * @type {Array}
 *
 * @properties={typeid:35,uuid:"28C276F2-18B8-47C5-ABEC-8CA6EF4CE6B8",variableType:-4}
 */
var array = new Array();


/**
 * Callback method for when form is shown.
 *
 * @param {Boolean} firstShow form is shown first time after load
 * @param {JSEvent} event the event that triggered the action
 *
 * @properties={typeid:24,uuid:"2B054DC9-B630-4680-9C43-294F4C408188"}
 */
function onShow(firstShow, event) {

	borrar_casillero();
	
	var num_records = databaseManager.getFoundSetCount(foundset);
	array = [];
	for (var x=1;x<=num_records;x++){
		
		/** @type {JSRecord<db:/casilleros/t100_productos>} */
		var jsrecord = foundset.getRecord(x);
		elements['btn_' + x].visible = true;
		elements['btn_' + x]['imageURL'] = 'media:///servoy_blobloader?datasource=' + controller.getDataSource() + '&dataprovider=thumbnail&mimetype=image/jpeg&rowid=' + jsrecord.id;
		elements['btn_' + x].toolTipText = jsrecord.calc_descripcion_html;
		array[x-1] = jsrecord.id;
	}
	
	application.output(array);
}

/**
 * @properties={typeid:24,uuid:"EE3E5789-A9D4-455D-B15E-D6D749DB3212"}
 */
function borrar_casillero(){
	
	for (var x=1;x<=16;x++){
		
		elements['btn_' + x].visible = false;
		elements['btn_' + x]['imageURL'] = null;
	}
}


/**
 * @param {JSEvent} event
 *
 * @properties={typeid:24,uuid:"883DF065-09CD-4807-96A5-FEA462354FFE"}
 */
function doEdit(event){
	
	globals.doEdit(controller.getName());
}

/**
 * @param {JSEvent} event
 *
 * @properties={typeid:24,uuid:"EAB17300-9AA3-4FB8-AE52-90C4FDB8D836"}
 */
function hide_btn_reset_fields(event){
	
	globals.hide_btn_reset_fields(controller.getName());
}

/**
 * Perform the element default action.
 *
 * @param {JSEvent} event the event that triggered the action
 *
 * @properties={typeid:24,uuid:"CD4C629C-9687-4E37-9A1B-9BEFEF73E2AC"}
 */
function btn_ir_ficha(event) {
	
	/** @type {JSFoundSet<db:/casilleros/t100_productos>} */
	var fs = databaseManager.getFoundSet("casilleros","t100_productos");
	/** @type {Number} */
	var _id = array[utils.stringToNumber(utils.stringReplace(event.getElementName(),"btn_",""))-1];
	
	fs.loadRecords(_id);
	globals.btnIrFicha(event,fs,forms.frm_t100_productos.controller.getName());
}
